﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Url.FriendlyUrl;

namespace company_present
{
    public partial class ListNews : ModuleCompanyBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.AddNew.Visible = DotNetNuke.Common.Globals.IsEditMode();

            if (Request["detail"] == null)
            {
                //kiem tra quyen hien nut them moi

                //gan dieu huong

                AddNew.NavigateUrl = EditUrl("AddNews");

                // liet ke 10 tin chay ban chay

                int currentPage = Request["page"] == null ? 1 : int.Parse(Request["page"].ToString());
                int pagSize=6;


                var context = DB;

                var news = from b in context.cp_News
                            where b.TabID == this.TabId && b.Visible.Value
                            orderby b.CreateDate descending
                            select b;
                //1 . chuyen truy van thanh list

                PagedList<cp_New> pl = new PagedList<cp_New>(news, currentPage-1, pagSize);

                //2 . gan vao repeater

                NewList.DataSource = pl.ToList();
                NewList.DataBind();

                //3 . chuyen thanh thanh phan trang

                Pager pg = new Pager(pagSize, currentPage, pl.TotalItemCount, TabId);

                //4. tao thanh phan trang

                pnPaging.Text = pg.RenderHtml();

            }

        }

        public string UrlImage(string name)
        {

            string rt = "";

            rt =  PortalSettings.HomeDirectory+ "Images/" + name;

            return rt;

        }
    }
}